<?php

Yii::import('application.models._base.BaseCustomerOrderBillingInfo');


class CustomerOrderBillingInfo extends BaseCustomerOrderBillingInfo
{
	public $credit_card_exp_year;
	public $credit_card_exp_month;
	public $credit_card_cvv;
	public $billing_payby;
	public $giftcard_check=0;
	
	public function attributeLabels(){
	    return array_merge(parent::attributeLabels(),array(
	        'credit_card_cvv' => Yii::t('app', 'CVV'),
	    ));
	}
	
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
	
	public function rules() {
		return array(
				array('billing_first_name, billing_last_name, billing_city, billing_phone,billing_email,billing_zip', 'required'),
				array('billing_address1', 'required','message'=>'Billing Address cannot be blank.'),
// 				array('gateway_customer_id, credit_card_num, credit_card_type, credit_card_exp, credit_card_cvv', 'required','message'=>'Required','on'=>'checkout'),
				array('billing_country, billing_state, created', 'numerical', 'integerOnly'=>true),
				array('billing_zip,billing_phone', 'numerical', 'integerOnly'=>true),
				// array('billing_zip', 'length', 'max'=>6),
// 				array('customer_id', 'length', 'max'=>10),
// 				array('credit_card_cvv','length','min'=>3,'max'=>4),
// 				array('billing_first_name, billing_last_name, billing_barangay, billing_city, billing_province, billing_region', 'length', 'max'=>100),
				array('billing_address1, billing_address2', 'length', 'max'=>200),
// 				array('credit_card_num', 'match', 'pattern' => '/^((4\d{12}(?:\d{3})?)|(5\d{15})|(34\d{13})|(37\d{13})|(6011\d{12}))$/'),
// // 				array('credit_card_num','length','min'=>15,'max'=>16),
// 				array('billing_zip, billing_phone, gateway_customer_id, credit_card_num, credit_card_type, credit_card_exp', 'length', 'max'=>45),
				array('billing_email', 'email'),
				array('billing_phone','match','pattern'=>'/^[0-9]{10}$/','message'=>'Phone wrong format'),
				array('billing_zip','match','pattern'=>'/^[0-9]{5}$/','message'=>'Zip wrong format'),
				array('giftcard_check,credit_card_cvv,id, customer_id, billing_first_name, billing_last_name, billing_address1, billing_address2, billing_barangay, billing_city, billing_province, billing_region, billing_country, billing_state, billing_zip, billing_phone, created, gateway_customer_id, credit_card_num, credit_card_type, credit_card_exp, billing_email', 'safe'),
		);
	}
	
	public function getFullAddress(){
		$country = Country::model()->findByPk($this->billing_country)->name;
		$state = State::model()->findByPk($this->billing_state)->name;
		return $this->billing_address1.' '.$this->billing_address2.' '.$this->billing_city.' '.$country.' '.$state.' '.$this->billing_zip;
	}
		
}